package com.car.advertising.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.car.advertising.R;
import com.car.advertising.activity.adapter.ReceiveRecordAdapter;
import com.car.advertising.connection.HttpUrl;
import com.car.advertising.entity.bean.ReceiveBean;
import com.support.widget.JumpManager;
import com.support.widget.layout.BaseRecylerViewToolBarActivity;
import com.support.widget.network.OkHttpClientManager;

import java.util.ArrayList;
import java.util.List;

public class ReceiveRecordActivity extends BaseRecylerViewToolBarActivity {

    private List<ReceiveBean> receiveBeanList = new ArrayList<>();
    private String taskId = "";
    private ReceiveRecordAdapter receiveRecordAdapter;

    @Override
    protected void initToolBar() {
        setToolBarBackgroundColor(R.color.color_white);
        setToolBarTitle("领取记录");
        setToolBarTitleColor(R.color.black_bg);

        setPullDownEnabled(false);
        setPullUpEnabled(false);
    }

    @Override
    protected void init() {

        Intent intent = getIntent();
        taskId = intent.getStringExtra("taskId");
        getRecordData();
        setReceiveData();
    }

    private void setReceiveData() {
        if (receiveRecordAdapter == null) {
            receiveRecordAdapter = new ReceiveRecordAdapter(ReceiveRecordActivity.this, receiveBeanList);
            initRecyclerView(receiveRecordAdapter);
        } else {
            receiveRecordAdapter.setRefreshList(receiveBeanList);
        }
    }

    private void getRecordData() {
        if (TextUtils.isEmpty(taskId)) {
            return;
        }
        List<OkHttpClientManager.Param> params = new ArrayList<>();
        params.add(new OkHttpClientManager.Param("taskId", taskId));
        OkHttpClientManager.postAsyn(HttpUrl.getInstance().URL_014, new OkHttpClientManager.ResultCallback<List<ReceiveBean>>() {
            @Override
            public void onError(String request) {
                if (TextUtils.equals(request, "登录已过期")) {
                    JumpManager.gotoActivity(ReceiveRecordActivity.this, LoginActivity.class, false);
                    finish();
                }
            }

            @Override
            public void onResponse(List<ReceiveBean> resp) {
                receiveBeanList = resp;
                setReceiveData();
            }

            @Override
            public void onFinish() {
            }
        }, params, null);
    }

    @Override
    protected boolean isClickable() {
        return false;
    }

    @Override
    protected void subtitleClick() {

    }

    @Override
    protected void titleClick() {

    }

    @Override
    protected void rightClick() {

    }


    @Override
    public String getCN() {
        return null;
    }

    @Override
    public void LogoutCallback(boolean islogin) {

    }

    @Override
    public void onCritClick(View v) {

    }

    @Override
    protected void onRefreshFinish() {

    }

    @Override
    protected void onLoadMoreFinish() {

    }
}
